<?php
// 应用公共文件
function cap2underline($string){
    //$string = "ThisIsAnExample";
    $convertedString = preg_replace('/([A-Z])/', '_$1', $string);
    $convertedString = strtolower($convertedString);
    return $convertedString = ltrim($convertedString, '_'); // 移除开头的下划线（如果需要的话）
    //echo $convertedString; // 输出：this_is_an_example
}
function R($status, $successData = [], $errorInfo = '')
{
    if (is_array($status) && $status) return json(['status' => 1, 'data' => $status]);
    if (is_numeric($status)) {
        return $status > 0 ? json(['status' => 1, 'data' => $successData]) : json(['status' => 0, 'info' => $errorInfo]);
    }
    if ($status) {
        if (is_string($successData)) {
            return json(['status' => 1, 'info' => $successData]);
        } else {
            return json(['status' => 1, 'data' => $successData]);
        }
    } else {
        return json(['status' => 0, 'info' => $errorInfo]);
    }
}

function getRandStr($count=6){
    $randSeed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    $str = "";
    for($i=0;$i<$count;$i++)$str.=substr($randSeed,rand(0,strlen($randSeed)-1),1);
    return $str;
}
